﻿using Hidistro.Entities.Commodities;
using Hidistro.Membership.Context;
using Hidistro.SaleSystem.Catalog;
using Hidistro.SaleSystem.Comments;
using Hidistro.UI.Common.Controls;
using Hidistro.UI.SaleSystem.Tags;
using System;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;

namespace Hidistro.UI.SaleSystem.CodeBehind
{
    public class JuseshangchengCategory : HtmlTemplatedWebControl
    {
        protected YB_Juseshangcheng_TowCategory PList;
        private HtmlGenericControl htmlp;
        private HtmlGenericControl mbx;

        protected override void AttachChildControls()
        {
            this.PList = (YB_Juseshangcheng_TowCategory)this.FindControl("list");
            this.htmlp = (HtmlGenericControl)this.FindControl("p");
            this.mbx = (HtmlGenericControl)this.FindControl("mbx");

            int cid = 0;
            if (this.Page.Request.QueryString["Cid"] != null)
            {
                cid = int.Parse(this.Page.Request.QueryString["Cid"]);
            }

            CategoryInfo category = CategoryBrowser.GetCategoryRewrite(cid);
            LoadPageSearch(category);
            List<CategoryInfo> list= CategoryBrowser.GetMaxSubCategories(cid,0x3e8) as List<CategoryInfo>;
            this.PList.DataSource=list;
            this.PList.DataBind();
            this.mbx.InnerHtml = "<a href='/' target=\"_blank\">橘色商城</a>&nbsp;&gt;&nbsp;<a href=\"/juse/index.html\" target=\"_blank\">成人用品</a>&nbsp;&gt;&nbsp;<a href=\"/juse/category-" + category.CategoryId + ".htm\"><h1>" + category.Name + "</h1></a>";
             htmlp.InnerHtml="所有分类：";
             foreach(CategoryInfo v in list)
             {
                 htmlp.InnerHtml += "<a target=\"_blank\" href=\"/juse/category/plist-" + v.CategoryId + ".htm\">" + v.Name + "</a>";
             }
        }
        private void LoadPageSearch(CategoryInfo category)
        {
            if (!string.IsNullOrEmpty(category.ReviewMeta_Keywords))
            {
                MetaTags.AddMetaKeywords(category.ReviewMeta_Keywords, HiContext.Current.Context);
            }
            if (!string.IsNullOrEmpty(category.ReviewMeta_Description))
            {
                MetaTags.AddMetaDescription(category.ReviewMeta_Description, HiContext.Current.Context);
            }
            if (!string.IsNullOrEmpty(category.ReviewMeta_Title))
            {
                PageTitle.AddSiteNameTitle(category.MetaTitle);
            }
            else
            {
                PageTitle.AddSiteNameTitle(category.Name);
            }
        }
        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "/juseshangcheng/Skin-JuseshangchengCategory.html";
            }
            base.OnInit(e);
        }
    }
}
